/**
 * 官方题解
 * @param {number} num
 * @return {string}
 */
var intToRoman = function (num) {
    const thousands = ["", "M", "MM", "MMM"];
    const hundreds = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"];
    const tens = ["", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"];
    const ones = ["", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"];
    const result = thousands[~~(num / 1000)] + hundreds[~~((num % 1000) / 100)] + tens[~~((num % 100) / 10)] + ones[~~((num % 10) / 1)];
    return result;
};

/**
 * 非常粗暴的解法,对所有情况做判断，每次减少原整数的大小
 * @param {number} num
 * @return {string}
 */
var intToRoman = function (num) {
    let romanMap = {
        "1000": "M",
        "500": "D",
        "100": "C",
        "50": "L",
        "10": "X",
        "5": "V",
        "1": "I",
    }, result = ""
    while (num > 0) {
        let digit = ~~num.toString()[0]
        let multiple = 1
        if (num / 10 >= 1) { multiple = 10 }
        if (num / 100 >= 1) { multiple = 100 }
        if (num / 1000 >= 1) { multiple = 1000 }


        if (digit === 9 || digit === 4) {
            result = result + romanMap[multiple] + romanMap[multiple * (digit + 1)]
            num -= digit * multiple
            continue
        }
        if (digit >= 5) {
            result = result + romanMap[multiple * 5]
            num -= 5 * multiple
            continue
        }
        result = result + romanMap[multiple]
        num -= multiple
    }
    return result
};
